package sudroid.json;

import java.io.IOException;
import java.io.Writer;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;

public class JSONArray
{
  private ArrayList myArrayList;

  public JSONArray()
  {
    ArrayList localArrayList = new ArrayList();
    this.myArrayList = localArrayList;
  }

  public JSONArray(Object paramObject)
    throws JSONException
  {
    this();
    if (paramObject.getClass().isArray())
    {
      int i = Array.getLength(paramObject);
      int j = 0;
      while (true)
      {
        if (j >= i)
          return;
        Object localObject = Array.get(paramObject, j);
        JSONArray localJSONArray = put(localObject);
        j += 1;
      }
    }
    throw new JSONException("JSONArray initial value should be a string or collection or array.");
  }

  public JSONArray(Object paramObject, boolean paramBoolean)
    throws JSONException
  {
    this();
    if (paramObject.getClass().isArray())
    {
      int i = Array.getLength(paramObject);
      int j = 0;
      while (true)
      {
        if (j >= i)
          return;
        Object localObject = Array.get(paramObject, j);
        JSONObject localJSONObject = new JSONObject(localObject, paramBoolean);
        JSONArray localJSONArray = put(localJSONObject);
        j += 1;
      }
    }
    throw new JSONException("JSONArray initial value should be a string or collection or array.");
  }

  public JSONArray(String paramString)
    throws JSONException
  {
    this(localJSONTokener);
  }

  public JSONArray(Collection paramCollection)
  {
    if (paramCollection == null);
    for (ArrayList localArrayList = new ArrayList(); ; localArrayList = new ArrayList(paramCollection))
    {
      this.myArrayList = localArrayList;
      return;
    }
  }

  public JSONArray(Collection paramCollection, boolean paramBoolean)
  {
    ArrayList localArrayList1 = new ArrayList();
    this.myArrayList = localArrayList1;
    Iterator localIterator;
    if (paramCollection != null)
      localIterator = paramCollection.iterator();
    while (true)
    {
      if (!localIterator.hasNext())
        return;
      ArrayList localArrayList2 = this.myArrayList;
      Object localObject = localIterator.next();
      JSONObject localJSONObject = new JSONObject(localObject, paramBoolean);
      boolean bool = localArrayList2.add(localJSONObject);
    }
  }

  public JSONArray(JSONTokener paramJSONTokener)
    throws JSONException
  {
    this();
    int i = paramJSONTokener.nextClean();
    int j;
    if (i == 91)
    {
      j = 93;
      if (paramJSONTokener.nextClean() != 93)
        break label47;
    }
    label47: 
    do
    {
      return;
      if (i == 40)
      {
        j = 41;
        break;
      }
      throw paramJSONTokener.syntaxError("A JSONArray text must start with '['");
      paramJSONTokener.back();
      while (true)
      {
        if (paramJSONTokener.nextClean() == 44)
        {
          paramJSONTokener.back();
          boolean bool1 = this.myArrayList.add(null);
        }
        while (true)
        {
          i = paramJSONTokener.nextClean();
          switch (i)
          {
          default:
            throw paramJSONTokener.syntaxError("Expected a ',' or ']'");
            paramJSONTokener.back();
            ArrayList localArrayList = this.myArrayList;
            Object localObject = paramJSONTokener.nextValue();
            boolean bool2 = localArrayList.add(localObject);
          case 44:
          case 59:
          case 41:
          case 93:
          }
        }
        if (paramJSONTokener.nextClean() == 93)
          break;
        paramJSONTokener.back();
      }
    }
    while (j == i);
    StringBuilder localStringBuilder = new StringBuilder("Expected a '");
    Character localCharacter = new Character(j);
    String str = localCharacter + "'";
    throw paramJSONTokener.syntaxError(str);
  }

  public Object get(int paramInt)
    throws JSONException
  {
    Object localObject = opt(paramInt);
    if (localObject == null)
    {
      String str = "JSONArray[" + paramInt + "] not found.";
      throw new JSONException(str);
    }
    return localObject;
  }

  public boolean getBoolean(int paramInt)
    throws JSONException
  {
    Object localObject = get(paramInt);
    Boolean localBoolean1 = Boolean.FALSE;
    if ((localObject.equals(localBoolean1)) || (((localObject instanceof String)) && (((String)localObject).equalsIgnoreCase("false"))));
    for (int i = 0; ; i = 1)
    {
      return i;
      Boolean localBoolean2 = Boolean.TRUE;
      if ((!localObject.equals(localBoolean2)) && ((!(localObject instanceof String)) || (!((String)localObject).equalsIgnoreCase("true"))))
        break;
    }
    String str = "JSONArray[" + paramInt + "] is not a Boolean.";
    throw new JSONException(str);
  }

  public double getDouble(int paramInt)
    throws JSONException
  {
    Object localObject = get(paramInt);
    String str;
    try
    {
      double d1;
      if ((localObject instanceof Number))
        d1 = ((Number)localObject).doubleValue();
      while (true)
      {
        return d1;
        double d2 = Double.valueOf((String)localObject).doubleValue();
        d1 = d2;
      }
    }
    catch (Exception localException)
    {
      str = "JSONArray[" + paramInt + "] is not a number.";
    }
    throw new JSONException(str);
  }

  public int getInt(int paramInt)
    throws JSONException
  {
    Object localObject = get(paramInt);
    if ((localObject instanceof Number));
    for (int i = ((Number)localObject).intValue(); ; i = (int)getDouble(paramInt))
      return i;
  }

  public JSONArray getJSONArray(int paramInt)
    throws JSONException
  {
    Object localObject = get(paramInt);
    if ((localObject instanceof JSONArray))
      return (JSONArray)localObject;
    String str = "JSONArray[" + paramInt + "] is not a JSONArray.";
    throw new JSONException(str);
  }

  public JSONObject getJSONObject(int paramInt)
    throws JSONException
  {
    Object localObject = get(paramInt);
    if ((localObject instanceof JSONObject))
      return (JSONObject)localObject;
    String str = "JSONArray[" + paramInt + "] is not a JSONObject.";
    throw new JSONException(str);
  }

  public long getLong(int paramInt)
    throws JSONException
  {
    Object localObject = get(paramInt);
    long l;
    if ((localObject instanceof Number))
      l = ((Number)localObject).longValue();
    while (true)
    {
      return l;
      l = ()getDouble(paramInt);
    }
  }

  public String getString(int paramInt)
    throws JSONException
  {
    return get(paramInt).toString();
  }

  public boolean isNull(int paramInt)
  {
    Object localObject1 = JSONObject.NULL;
    Object localObject2 = opt(paramInt);
    return localObject1.equals(localObject2);
  }

  public String join(String paramString)
    throws JSONException
  {
    int i = length();
    StringBuffer localStringBuffer1 = new StringBuffer();
    int j = 0;
    while (true)
    {
      if (j >= i)
        return localStringBuffer1.toString();
      if (j > 0)
        StringBuffer localStringBuffer2 = localStringBuffer1.append(paramString);
      String str = JSONObject.valueToString(this.myArrayList.get(j));
      StringBuffer localStringBuffer3 = localStringBuffer1.append(str);
      j += 1;
    }
  }

  public int length()
  {
    return this.myArrayList.size();
  }

  public Object opt(int paramInt)
  {
    if (paramInt >= 0)
    {
      int i = length();
      if (paramInt < i)
        break label18;
    }
    label18: for (Object localObject = null; ; localObject = this.myArrayList.get(paramInt))
      return localObject;
  }

  public boolean optBoolean(int paramInt)
  {
    return optBoolean(paramInt, 0);
  }

  public boolean optBoolean(int paramInt, boolean paramBoolean)
  {
    try
    {
      boolean bool1 = getBoolean(paramInt);
      bool2 = bool1;
      return bool2;
    }
    catch (Exception localException)
    {
      while (true)
        boolean bool2 = paramBoolean;
    }
  }

  public double optDouble(int paramInt)
  {
    return optDouble(paramInt, (0.0D / 0.0D));
  }

  public double optDouble(int paramInt, double paramDouble)
  {
    try
    {
      double d1 = getDouble(paramInt);
      d2 = d1;
      return d2;
    }
    catch (Exception localException)
    {
      while (true)
        double d2 = paramDouble;
    }
  }

  public int optInt(int paramInt)
  {
    return optInt(paramInt, 0);
  }

  public int optInt(int paramInt1, int paramInt2)
  {
    try
    {
      int i = getInt(paramInt1);
      j = i;
      return j;
    }
    catch (Exception localException)
    {
      while (true)
        int j = paramInt2;
    }
  }

  public JSONArray optJSONArray(int paramInt)
  {
    Object localObject = opt(paramInt);
    if ((localObject instanceof JSONArray));
    for (JSONArray localJSONArray = (JSONArray)localObject; ; localJSONArray = null)
      return localJSONArray;
  }

  public JSONObject optJSONObject(int paramInt)
  {
    Object localObject = opt(paramInt);
    if ((localObject instanceof JSONObject));
    for (JSONObject localJSONObject = (JSONObject)localObject; ; localJSONObject = null)
      return localJSONObject;
  }

  public long optLong(int paramInt)
  {
    return optLong(paramInt, 0L);
  }

  public long optLong(int paramInt, long paramLong)
  {
    try
    {
      long l1 = getLong(paramInt);
      l2 = l1;
      return l2;
    }
    catch (Exception localException)
    {
      while (true)
        long l2 = paramLong;
    }
  }

  public String optString(int paramInt)
  {
    return optString(paramInt, "");
  }

  public String optString(int paramInt, String paramString)
  {
    Object localObject = opt(paramInt);
    if (localObject != null);
    for (String str = localObject.toString(); ; str = paramString)
      return str;
  }

  public JSONArray put(double paramDouble)
    throws JSONException
  {
    Double localDouble = new Double(paramDouble);
    JSONObject.testValidity(localDouble);
    JSONArray localJSONArray = put(localDouble);
    return this;
  }

  public JSONArray put(int paramInt)
  {
    Integer localInteger = new Integer(paramInt);
    JSONArray localJSONArray = put(localInteger);
    return this;
  }

  public JSONArray put(int paramInt, double paramDouble)
    throws JSONException
  {
    Double localDouble = new Double(paramDouble);
    JSONArray localJSONArray = put(paramInt, localDouble);
    return this;
  }

  public JSONArray put(int paramInt1, int paramInt2)
    throws JSONException
  {
    Integer localInteger = new Integer(paramInt2);
    JSONArray localJSONArray = put(paramInt1, localInteger);
    return this;
  }

  public JSONArray put(int paramInt, long paramLong)
    throws JSONException
  {
    Long localLong = new Long(paramLong);
    JSONArray localJSONArray = put(paramInt, localLong);
    return this;
  }

  public JSONArray put(int paramInt, Object paramObject)
    throws JSONException
  {
    JSONObject.testValidity(paramObject);
    if (paramInt < 0)
    {
      String str = "JSONArray[" + paramInt + "] not found.";
      throw new JSONException(str);
    }
    int i = length();
    if (paramInt < i)
      Object localObject1 = this.myArrayList.set(paramInt, paramObject);
    while (true)
    {
      return this;
      int j;
      do
      {
        Object localObject2 = JSONObject.NULL;
        JSONArray localJSONArray1 = put(localObject2);
        j = length();
      }
      while (paramInt != j);
      JSONArray localJSONArray2 = put(paramObject);
    }
  }

  public JSONArray put(int paramInt, Collection paramCollection)
    throws JSONException
  {
    JSONArray localJSONArray1 = new JSONArray(paramCollection);
    JSONArray localJSONArray2 = put(paramInt, localJSONArray1);
    return this;
  }

  public JSONArray put(int paramInt, Map paramMap)
    throws JSONException
  {
    JSONObject localJSONObject = new JSONObject(paramMap);
    JSONArray localJSONArray = put(paramInt, localJSONObject);
    return this;
  }

  public JSONArray put(int paramInt, boolean paramBoolean)
    throws JSONException
  {
    if (paramBoolean);
    for (Boolean localBoolean = Boolean.TRUE; ; localBoolean = Boolean.FALSE)
    {
      JSONArray localJSONArray = put(paramInt, localBoolean);
      return this;
    }
  }

  public JSONArray put(long paramLong)
  {
    Long localLong = new Long(paramLong);
    JSONArray localJSONArray = put(localLong);
    return this;
  }

  public JSONArray put(Object paramObject)
  {
    boolean bool = this.myArrayList.add(paramObject);
    return this;
  }

  public JSONArray put(Collection paramCollection)
  {
    JSONArray localJSONArray1 = new JSONArray(paramCollection);
    JSONArray localJSONArray2 = put(localJSONArray1);
    return this;
  }

  public JSONArray put(Map paramMap)
  {
    JSONObject localJSONObject = new JSONObject(paramMap);
    JSONArray localJSONArray = put(localJSONObject);
    return this;
  }

  public JSONArray put(boolean paramBoolean)
  {
    if (paramBoolean);
    for (Boolean localBoolean = Boolean.TRUE; ; localBoolean = Boolean.FALSE)
    {
      JSONArray localJSONArray = put(localBoolean);
      return this;
    }
  }

  public JSONObject toJSONObject(JSONArray paramJSONArray)
    throws JSONException
  {
    Object localObject1;
    if ((paramJSONArray == null) || (paramJSONArray.length() == 0) || (length() == 0))
    {
      localObject1 = null;
      return localObject1;
    }
    JSONObject localJSONObject1 = new JSONObject();
    int i = 0;
    while (true)
    {
      int j = paramJSONArray.length();
      if (i >= j)
      {
        localObject1 = localJSONObject1;
        break;
      }
      String str = paramJSONArray.getString(i);
      Object localObject2 = opt(i);
      JSONObject localJSONObject2 = localJSONObject1.put(str, localObject2);
      i += 1;
    }
  }

  public String toString()
  {
    try
    {
      String str1 = String.valueOf(91);
      StringBuilder localStringBuilder = new StringBuilder(str1);
      String str2 = join(",");
      String str3 = str2 + 93;
      str4 = str3;
      return str4;
    }
    catch (Exception localException)
    {
      while (true)
        String str4 = null;
    }
  }

  public String toString(int paramInt)
    throws JSONException
  {
    return toString(paramInt, 0);
  }

  String toString(int paramInt1, int paramInt2)
    throws JSONException
  {
    int i = length();
    String str1;
    if (i == 0)
    {
      str1 = "[]";
      return str1;
    }
    StringBuffer localStringBuffer1 = new StringBuffer("[");
    if (i == 1)
    {
      String str2 = JSONObject.valueToString(this.myArrayList.get(0), paramInt1, paramInt2);
      StringBuffer localStringBuffer2 = localStringBuffer1.append(str2);
    }
    int j;
    int k;
    while (true)
    {
      StringBuffer localStringBuffer3 = localStringBuffer1.append(93);
      str1 = localStringBuffer1.toString();
      break;
      j = paramInt2 + paramInt1;
      StringBuffer localStringBuffer4 = localStringBuffer1.append(10);
      k = 0;
      if (k < i)
        break label139;
      StringBuffer localStringBuffer5 = localStringBuffer1.append(10);
      k = 0;
      while (k < paramInt2)
      {
        StringBuffer localStringBuffer6 = localStringBuffer1.append(32);
        k += 1;
      }
    }
    label139: if (k > 0)
      StringBuffer localStringBuffer7 = localStringBuffer1.append(",\n");
    int m = 0;
    while (true)
    {
      if (m >= j)
      {
        String str3 = JSONObject.valueToString(this.myArrayList.get(k), paramInt1, j);
        StringBuffer localStringBuffer8 = localStringBuffer1.append(str3);
        k += 1;
        break;
      }
      StringBuffer localStringBuffer9 = localStringBuffer1.append(32);
      m += 1;
    }
  }

  public Writer write(Writer paramWriter)
    throws JSONException
  {
    int i = 0;
    while (true)
    {
      Object localObject;
      try
      {
        int j = length();
        paramWriter.write(91);
        int k = 0;
        if (k < j)
          continue;
        paramWriter.write(93);
        return paramWriter;
        if (i == 0)
          continue;
        paramWriter.write(44);
        localObject = this.myArrayList.get(k);
        if (!(localObject instanceof JSONObject))
          continue;
        Writer localWriter1 = ((JSONObject)localObject).write(paramWriter);
        i = 1;
        k += 1;
        continue;
        if ((localObject instanceof JSONArray))
        {
          Writer localWriter2 = ((JSONArray)localObject).write(paramWriter);
          continue;
        }
      }
      catch (IOException localIOException)
      {
        throw new JSONException(localIOException);
      }
      String str = JSONObject.valueToString(localObject);
      paramWriter.write(str);
    }
  }
}

/* Location:           D:\Program Files\eclipse\apktool-r01-3\新浪微博\classes.dex.dex2jar.jar
 * Qualified Name:     sudroid.json.JSONArray
 * JD-Core Version:    0.6.0
 */